Skip to content

Conversation

@eregon
Copy link
Member

@eregon eregon commented Jan 29, 2026

@eregon eregon requested review from Earlopain and kddnewton January 29, 2026 19:41
@eregon eregon force-pushed the ripper-sexp-coerce branch from 5bbfbcf to 6e1d9e9 Compare January 29, 2026 19:52
Copy link
Collaborator

@Earlopain Earlopain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the rules are a bit more complex: https://github.com/ruby/ruby/blob/acc414572c213f2690eee56bac3d2355a24e5930/ext/ripper/ripper_init.c.tmpl#L357-L376

Do you want to implement those also? File should be easy at least.

@eregon
Copy link
Member Author

eregon commented Jan 29, 2026

It looks like the rules are a bit more complex: https://github.com/ruby/ruby/blob/acc414572c213f2690eee56bac3d2355a24e5930/ext/ripper/ripper_init.c.tmpl#L357-L376

Do you want to implement those also? File should be easy at least.

I see. If you want to do it feel free to push to this branch, otherwise I can get to it tomorrow or so.

@Earlopain
Copy link
Collaborator

Tomorrow is fine

@eregon eregon force-pushed the ripper-sexp-coerce branch from 6e1d9e9 to a83cb7b Compare January 30, 2026 11:58
@eregon
Copy link
Member Author

eregon commented Jan 30, 2026

Done, now it also handles IO object (= T_FILE) and #gets objects, same logic as upstream.

@eregon eregon requested a review from Earlopain January 30, 2026 11:59
@eregon eregon changed the title Handle String-like objects for Ripper.sexp Handle String-like and IO-like objects for Ripper.sexp Jan 30, 2026
def initialize(source, filename = "(ripper)", lineno = 1)
@source = source
if source.is_a?(IO)
@source = source.read
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be backed by Prism.parse_stream but since we need the whole source anyways I think this is fine. BTW, wouldn't work for the gets case since prism also expects eof? to be present

end
else
@source = source.to_str
end

This comment was marked as duplicate.

@kddnewton kddnewton merged commit 62c7300 into ruby:main Jan 30, 2026
66 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants